// 递归扫描一个目录，列出所有的文件
package main

import (
	"errors"
	"fmt"
	"io/ioutil"
	"log"
	"path"
)

// 递归，只是打印
func scanDataDir(dirName string) {
	fmt.Println("dir: ", dirName)
	files, err := ioutil.ReadDir(dirName)
	if err != nil {
		log.Fatal(err)
	}
	for _, file := range files {
		filePath := path.Join(dirName, file.Name())
		if file.IsDir() {
			scanDataDir(filePath)
			panic(errors.New("scan data dir error" + filePath))
		} else {
			fmt.Println("file: ", filePath)
		}
	}
}

func main() {
	fmt.Println("all begin")
	defer myRecover()
	scanDataDir("mydir")
	fmt.Println("all end")
}

func myRecover() {
	fmt.Println("recover: ", recover())
}
